<script lang="ts">
import { defineComponent } from 'vue';
import { ARCO_ICON_PREFIX, LOCAL_ICON_PREFIX } from './index';
import * as AntIcons from '@arco-design/web-vue/es/icon';
import { createVNode, h } from 'vue';
import svgIcon from './svg-icon.vue'

export default defineComponent({
    name: 'Icon',
    props: {
        name: {
            type: String,
            required: true
        },
        size: {
            type: [String, Number],
            default: "16px",
        },
        color: {
            type: String,
            default: "inherit"
        }
    },
    setup(props) {
        return () => {
            if (props.name && props.name.indexOf(ARCO_ICON_PREFIX) === 0) {
                const iconName = props.name.replace(ARCO_ICON_PREFIX, '');
                // @ts-ignore
                const AntIcon = AntIcons[iconName];
                if (AntIcon) {
                    return createVNode(AntIcon, {
                        style: {
                            fontSize: typeof props.size === 'number' ? `${props.size}px` : props.size,
                            color: props.color
                        }
                    });
                }
            }

            if (props.name && props.name.indexOf(LOCAL_ICON_PREFIX) === 0) {
                const iconName = props.name;
                console.log(iconName)
                return h(svgIcon, {
                    name: `${iconName}`,
                    size: props.size,
                    color: props.color,
                    class: 'svg-icon'
                });
            }

            return null;

        }
    }
})
</script>
